/* eslint-env mocha */
'use strict';

process.env.NODE_ENV = 'test';

const supertest = require('co-supertest');
const path = require('path');
const app = require('../../server/app');
const config = require('../../server/config');

const port = config.app.port;
const baseUrl = 'http://localhost:' + port + '/api/v1';

exports.baseUrl = baseUrl;
exports.supertest = supertest;
exports.request = supertest(baseUrl);
// agent: admin areadly login
exports.agent = supertest.agent(baseUrl);
exports.root = path.resolve(__dirname);
console.log('root:', exports.root);

before(function * () {
  // this.timeout(10000)
  // yield app.init()
  app.server = app.listen(port);
  console.log('test is listening port: ' + port);

  const userHelper = require('./helper/user');
  yield userHelper.create;
// admin login
// userHelper.signAgent(exports.agent, done)
// done()
});

after(function * (done) {
  const databaseHelper = require('./helper/database');
  yield databaseHelper.drop();

  app.server.close(done);
  console.log('test closed server and exit!');
});
